#include "niveau.h"
int charger_niveau(char chemin[],int grille[][nbre_case],int *x,int *y)
{
    FILE *f;
    int i,j;
    char ligne[nbre_case*nbre_case+1]={0};
    f=fopen(chemin,"r");
    if(f==NULL)return 0;
    else
    {
        fgets(ligne,nbre_case*nbre_case+1,f);
        for(i=0;i<nbre_case;i++)
            for(j=0;j<nbre_case;j++)
            {
                switch(ligne[(i*nbre_case)+j])
                    {
                        case '0' : grille[j][i]=0;  break;
                        case '1' : grille[j][i]=1;  break;
                        case '2' : grille[j][i]=2;  break;
                        case '3' : grille[j][i]=3;  break;
                        case '4' : grille[j][i]=4;  break;
                        case '5' : grille[j][i]=5;  break;
                        case '6' : {grille[j][i]=6;} break;
                        case '7' : {grille[j][i]=7;} break;
                        case '8' : {grille[j][i]=8;} break;
                        case '9' : {grille[j][i]=9;} break;
                        case '-1' : grille[j][i]=-1;  break;
                        case '-2' : grille[j][i]=-2;  break;
                        case '-3' : grille[j][i]=-3;  break;
                        case '-4' : grille[j][i]=-4;  break;



                    }

            }
        fclose(f);
        return 1;
    }
}
int sauvegarger_niveau(int grille[][nbre_case],int x_pos_pion,int y_pos_pion)
{
    int i,j;
    FILE *f;
    char chemin[]="sauvegarde.lvl";

    f=fopen(chemin,"w");
    if (f==NULL)return 0;
    else
    {
        for(i=0;i<nbre_case;i++)
            for(j=0;j<nbre_case;j++)
            {
                if((j==x_pos_pion)&&(i==y_pos_pion)) fprintf(f,"%d",grille[j][i]+5);
                else    fprintf(f,"%d",grille[j][i]);
            }

    fclose(f);
    return 1;
    }
}
